<script setup>
import useLocale from '@/composables/useLocale'
import { ref } from 'vue'
const { VITE_DEFAULT_AI_MODEL } = import.meta.env

function handlePhoneBtnClick() {
    uni.navigateTo({
        url: '/pages/auth/login-by-phone',
    })
}

const { t } = useLocale()

const wxLoading = ref(false)
function handleWxLogin() {
    wxLoading.value = true
    // #ifdef MP-WEIXIN
    uni.login({
        provider: 'weixin',
        success: (res) => {
            console.log('login success', res)
            wxLoading.value = false
            uni.redirectTo({
                url: `/pages/index/index?chatMode=${VITE_DEFAULT_AI_MODEL}`,
            })
        },
        fail: (err) => {
            console.log('login fail', err)
        },
    })
    // #endif
}
</script>
<template>
    <view
        class="mx-auto flex h-full max-w-96 flex-col justify-center gap-2 px-4"
    >
        <button
            class="flex w-full items-center justify-center rounded-full bg-zinc-950 py-3 text-base text-zinc-50"
            @click="handlePhoneBtnClick"
        >
            {{ t('loginByPhone') }}
        </button>
        <navigator url="/pages/auth/login-by-email">
            <button
                class="flex w-full items-center justify-center rounded-full bg-zinc-950 py-3 text-base text-zinc-50"
            >
                {{ t('loginByEmail') }}
            </button>
        </navigator>
        <button
            class="flex w-full items-center justify-center rounded-full bg-green-600 py-3 text-base text-zinc-50"
            :loading="wxLoading"
            @click="handleWxLogin"
        >
            {{ t('loginByWeChat') }}
        </button>
    </view>
</template>

<style>
page {
    height: 100%;
}
</style>
